/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.mongodb.optimization;

import com.facebook.airlift.log.Logger;
import com.facebook.presto.mongodb.MongoTableLayoutHandle;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.TableHandle;
import com.facebook.presto.spi.VariableAllocator;
import com.facebook.presto.spi.adaptive.CatalogEngine;
import com.facebook.presto.spi.adaptive.ConnectorAdaptiveOptimizer;
import com.facebook.presto.spi.adaptive.metadata.presto.AdaptivePrestoObject;
import com.facebook.presto.spi.plan.PlanNode;
import com.facebook.presto.spi.plan.PlanNodeIdAllocator;
import com.facebook.presto.spi.plan.TableScanNode;

public class MongoTestPushdown
        implements ConnectorAdaptiveOptimizer
{
    private static final Logger log = Logger.get(MongoTestPushdown.class);

    public PlanNode adaptiveOptimize(PlanNode maxSubplan, ConnectorSession session, VariableAllocator variableAllocator, PlanNodeIdAllocator idAllocator)
    {
        log.info("MongoTestPushDown-bingo!");
        if(maxSubplan instanceof TableScanNode)
        {
            TableScanNode node = (TableScanNode)maxSubplan;
            MongoTableLayoutHandle layout = (MongoTableLayoutHandle)node.getTable().getLayout().get();
            layout.setAddition("test");
        }
        return maxSubplan;
    }

    @Override
    public CatalogEngine getConnectorCatalog()
    {
        return null;
    }

    @Override
    public PlanNode adaptiveOptimize(PlanNode node, TableHandle tableHandle, PlanNodeIdAllocator idAllocator, AdaptivePrestoObject adaptiveObject)
    {
        return null;
    }
}
